﻿/*
 * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
 */

#include "BurnCtrlWorker.h"
#include <QDebug>
#include "BurnToolCommon/Global.h"

BurnCtrlWorkerClass::BurnCtrlWorker::BurnCtrlWorker(QObject *parent)
    : QObject(parent),
      witeThreadMsgId(0)
{
    qRegisterMetaType<LPVOID>("LPVOID");
    qRegisterMetaType<WPARAM>("WPARAM");
    qRegisterMetaType<LPARAM>("LPARAM");
}

void BurnCtrlWorkerClass::BurnCtrlWorker::SlotSendMsg(long int msgId, WPARAM wParam, LPARAM lParam)
{
    if (!thread()->isRunning()) {
        return;
    }
    if (msgId == witeThreadMsgId) {
        emit SignalCommunication(wParam, lParam);
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_KILLALLTIMER)) {
        emit SignalKillAllTimer();
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_SHOWRESULT)) {
        emit SignalShowResult();
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_SETRESULT)) {
        emit SignalSetResult(wParam);
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_SETRESULT_A2B)) {
        emit SignalSetResultFromAToB(wParam,  lParam);
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_RESETUIANDFSM)) {
        emit SignalResetUIAndFSM();
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_INITBURNCMD)) {
        emit SignalInitBurnCmd();
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_STARTCONNECT)) {
        emit SignalStartConnect();
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_RESETBURNSTATE)) {
        emit SignalResetBurnState();
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_EXIT)) {
        emit SignalExitApp(wParam, lParam);
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_CLOSE_JLINK)) {
        emit SignalCloseJlink();
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_EXPORT)) {
        emit SignalExport(wParam, lParam);
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_COMMON_ACTION1)) {
        emit SignalCommonAction1();
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_COMMON_ACTION2)) {
        emit SignalCommonAction2();
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_COMMON_ACTION3)) {
        emit SignalCommonAction3();
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_ERASE_ALL)) {
        emit SignalEraseAll();
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_MCU_REOPEN)) {
        emit SignalMcuReopen();
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_STARTBURN)) {
        emit SignalStartBurn();
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_ERASE)) {
        emit SignalErase(wParam, lParam);
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_GET_PARAMETER)) {
        emit SignalGetParameter();
    } else if (msgId == static_cast<long int>(WiteThreadMsg::WITE_THREAD_MSG_SET_PARAMETER)) {
        emit SignalSetParameter();
    }
}

void BurnCtrlWorkerClass::BurnCtrlWorker::SetWiteThreadMsgId(long int witeThreadMsgIdBcw)
{
    this->witeThreadMsgId = witeThreadMsgIdBcw;
}
